package com.ruoyi.dzzh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dzzh.domain.DzzhYjya;
import com.ruoyi.dzzh.service.IDzzhYjyaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急预案Controller
 * 
 * @author cjt
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/dzzh/yjya")
public class DzzhYjyaController extends BaseController
{
    @Autowired
    private IDzzhYjyaService dzzhYjyaService;

    /**
     * 查询应急预案列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:yjya:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzzhYjya dzzhYjya)
    {
        startPage();
        List<DzzhYjya> list = dzzhYjyaService.selectDzzhYjyaList(dzzhYjya);
        return getDataTable(list);
    }

    /**
     * 导出应急预案列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:yjya:export')")
    @Log(title = "应急预案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzzhYjya dzzhYjya)
    {
        List<DzzhYjya> list = dzzhYjyaService.selectDzzhYjyaList(dzzhYjya);
        ExcelUtil<DzzhYjya> util = new ExcelUtil<DzzhYjya>(DzzhYjya.class);
        util.exportExcel(response, list, "应急预案数据");
    }

    /**
     * 获取应急预案详细信息
     */
    @PreAuthorize("@ss.hasPermi('dzzh:yjya:query')")
    @GetMapping(value = "/{yjyaId}")
    public AjaxResult getInfo(@PathVariable("yjyaId") Long yjyaId)
    {
        return AjaxResult.success(dzzhYjyaService.selectDzzhYjyaByYjyaId(yjyaId));
    }

    /**
     * 新增应急预案
     */
    @PreAuthorize("@ss.hasPermi('dzzh:yjya:add')")
    @Log(title = "应急预案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzzhYjya dzzhYjya)
    {
        return toAjax(dzzhYjyaService.insertDzzhYjya(dzzhYjya));
    }

    /**
     * 修改应急预案
     */
    @PreAuthorize("@ss.hasPermi('dzzh:yjya:edit')")
    @Log(title = "应急预案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzzhYjya dzzhYjya)
    {
        return toAjax(dzzhYjyaService.updateDzzhYjya(dzzhYjya));
    }

    /**
     * 删除应急预案
     */
    @PreAuthorize("@ss.hasPermi('dzzh:yjya:remove')")
    @Log(title = "应急预案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{yjyaIds}")
    public AjaxResult remove(@PathVariable Long[] yjyaIds)
    {
        return toAjax(dzzhYjyaService.deleteDzzhYjyaByYjyaIds(yjyaIds));
    }
}
